package com.one.group.admin.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.one.group.admin.dao.AdvertDao;
import com.one.group.admin.mapper.HomeMapper;
import com.one.group.model.vo.HomePriceVo;
import com.one.group.service.HomeService;
import com.one.group.service.SpPredepositSercive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class HomeServiceImpl implements HomeService {
    @Autowired
    private HomeMapper homeMapper;
    @Autowired
    private SpPredepositSercive spPredepositSercive;
    @Autowired
    private AdvertDao advertDao;
    @Override
    public HomePriceVo getHomePrice() {
        Long tenantId = Convert.toLong(StpUtil.getExtra("tenant_id"));
        HomePriceVo homePriceVo = new HomePriceVo();
        try {
            homePriceVo.setUnpaidPrice(homeMapper.getUnpaidPrice(tenantId));
            homePriceVo.setTotalRepairPrice(homeMapper.getTotalRepairPrice(tenantId));
            homePriceVo.setTotalDeposit((BigDecimal) spPredepositSercive.totalamount());
            homePriceVo.setTotalAdvertPrice(advertDao.getTotalPrice());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return homePriceVo;
    }
}
